<?php

namespace App\Repositories;

use App\Exceptions\BasicException;
use Illuminate\Support\Facades\Hash;
use function Matrix\add;    //引入hash

class LisenceTagRepository {
    /**
     * 资质标签分类列表
     * @param  $param
     * @return bool
     */
    public function tagTypeList($param) {
        $list = app('model_lisence_tag')
            ->with('lisence:lisence_id,lisence_name')
            ->where('lisence_id', $param['lisence_id']);
        if ($param['type'] == 1) {
            $list = $list->where('pid', 0);
        }
        if ($param['type'] == 2) {
            $list = $list->where('pid', '<>', 0);
        }
        $list = $list->orderBy('sort', 'desc')
            ->orderBy('add_time', 'desc')
            ->get()->toArray();
        return $list;
    }

    /**
     * 新增资质分类标签
     * @param  $param
     * @return bool
     * @throws BasicException
     */
    public function addTypeTag($param) {
        $add = app('model_lisence_tag')->create($param);
        if ($add) return $add;
        throw new  BasicException(93134);
    }

    /**
     * 编辑资质分类标签
     * @param  $param
     * @return bool
     * @throws BasicException
     */
    public function saveTypeTag($param) {
        $save = app('model_lisence_tag')->where('tag_id',$param['tag_id'])->update($param);
        if ($save!==false) return true;
        throw new  BasicException(93135);
    }

    /**
     * 删除资质分类标签
     * @param  $param
     * @return bool
     * @throws BasicException
     */
    public  function  delTypeTag($param){
        $del = app('model_lisence_tag')->whereIn('tag_id',$param)->delete();
        if ($del) return $del;
        throw new  BasicException(93136);

    }

    /**
     * 获取资质标签详情
     * @param  $tag_id
     * @return bool
     * @throws BasicException
     */
    public  function  getDetail($tag_id){
        $detail = app('model_lisence_tag')->where('tag_id',$tag_id)->first();
        if ($detail) return $detail;
        throw new  BasicException(93137);
    }



    /**
     * 获取父级分类标签列表
     * @param  $lisence_id
     * @return bool
     * @throws BasicException
     */
    public  function  parentTagList($lisence_id){
        $list = app('model_lisence_tag')->where('pid',0)->where('lisence_id',$lisence_id)->select('tag_id','tag_name')->get()->toArray();
        if ($list)  return $list;
        throw new  BasicException(93141);
    }


    /**
     * 获取名称
     * @param  $id
     * @return bool
     * @throws BasicException
     */
    public  function  getName($id){
        $name = app('model_lisence_tag')->where('tag_id',$id)->value('tag_name');
        return $name;
    }


    /**
     * 获取标签列表
     * @param  $param
     * @return bool
     * @throws BasicException
     */
    public  function  tagList($param){
        $name = app('model_lisence_tag')->whereIn('tag_id',$param)->pluck('tag_name','tag_id')->toArray();
        return $name;
    }

}


?>